#include <iostream>
#include <sstream>
#include <string>
#include <queue>
using namespace std;

class TreeNode
{
public:
    int val;
    vector<TreeNode*> children;
    TreeNode() {}
    TreeNode(int _val)
    {
        val = _val;
    }
    TreeNode(int _val, vector<TreeNode*> _children)
    {
        val = _val;
        children = _children;
    }
};
TreeNode* inputTree()
{
    int n, count = 0;
    char item[100];
    cin >> n;
    if (n == 0)
        return NULL;
    cin >> item;
    TreeNode* root = new TreeNode(atoi(item));
    count++;
    queue<TreeNode*> nodeQueue;
    nodeQueue.push(root);
    cin >> item;
    count++;
    while (count < n)
    {
        TreeNode* node = nodeQueue.front();
        nodeQueue.pop();
        cin >> item;
        count++;
        if (strcmp(item, "null") == 0) {
            continue;
        }
        else {
            while (strcmp(item, "null") != 0 && count <= n)
            {
                TreeNode* temp = new TreeNode(atoi(item));
                node->children.push_back(temp);
                nodeQueue.push(temp);
                if (count == n)
                    break;
                cin >> item;
                count++;
            }
        }
    }
    return root;
}
typedef TreeNode Node;

void p(Node* h)
{
    queue<Node*> q;
    q.push(h);
    while (q.size()) {
        int k = q.size();
        while (k--) {
            auto cur = q.front(); q.pop();
            cout << cur->val << " ";
            for (auto e : cur->children) {
                if(e) q.push(e);
            }
        }   cout << endl;
    }
}

int main()
{
    Node* h = inputTree();
    p(h);
	return 0;
}